home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DllSys_Files / THRESHTR / THRESHT.C
Encoding:
C/C++ Source or Header  |  2002-03-08  |  2.6 KB  |  97 lines

  1. // Dynamic link library implementation of NeuroSolutions ThresholdTransmitter component
  2.  
  3. #include "NSDLL.h"
  4.  
  5. BOOL averageLessThan(NSFloat *, int, NSFloat);
  6. BOOL allLessThan(NSFloat *, int, NSFloat);
  7. BOOL oneLessThan(NSFloat *, int, NSFloat);
  8.  
  9. /******************************************/
  10. /* Decide when to send transmitter action */
  11.  
  12. __declspec(dllexport) BOOL performThresholdTransmitter(
  13.     DLLData    *instance,    // Pointer to instance data (may be NULL)
  14.     NSFloat    *data,         // Pointer to the data to be accessed
  15.     int     rows,        // Number of rows of access data
  16.     int     cols,        // Number of columns of access data
  17.     NSFloat    threshold,     // Threshold specified within the compontents inspector
  18.     BOOL    lessThan,     // Less than/greater than state as specified within inspector
  19.     int        type,         // Threshold type, 0=All 1=One 2=Average 3=Individual
  20.     int     channelNumber
  21.     )
  22. {
  23.     int length=rows*cols;
  24.  
  25.     switch (type) {
  26.         case 0:
  27.             if (lessThan)
  28.                 return allLessThan(data,length,threshold);
  29.             return !oneLessThan(data,length,threshold);
  30.             break;
  31.         case 1:
  32.             if (lessThan)
  33.                 return oneLessThan(data,length,threshold);
  34.             return !allLessThan(data,length,threshold);
  35.             break;
  36.         case 2:
  37.             if (lessThan)
  38.                 return averageLessThan(data,length,threshold);
  39.             return !averageLessThan(data,length,threshold);
  40.             break;
  41.         case 3:
  42.             if (lessThan)
  43.                 return oneLessThan(data+channelNumber,1,threshold);
  44.             return !allLessThan(data+channelNumber,1,threshold);
  45.             break;
  46.     }
  47.     return NO;
  48. }
  49.  
  50. BOOL oneLessThan(NSFloat *data, int length, NSFloat threshold)
  51. {
  52.     register int i;
  53.  
  54.     for (i=0; i<length; i++)
  55.         if (data[i] < threshold)
  56.             return YES;
  57.     return NO;
  58. }
  59.  
  60. BOOL allLessThan(NSFloat *data, int length, NSFloat threshold)
  61. {
  62.     register int i;
  63.  
  64.     for (i=0; i<length; i++)
  65.         if (data[i] > threshold)
  66.             return NO;
  67.     return YES;
  68. }
  69.  
  70. BOOL averageLessThan(NSFloat *data, int length, NSFloat threshold)
  71. {
  72.     register int i;
  73.     register NSFloat average = (NSFloat)0.0;
  74.  
  75.     for (i=0; i<length; i++)
  76.         average += data[i];
  77.     return (average /= length) < threshold;
  78. }
  79.  
  80. /******************************************/
  81. /* Management of instance data (OPTIONAL) */
  82. /*
  83. __declspec(dllexport) DLLData *allocThresholdTransmitter(
  84.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  85.     int     rows,        // Number of rows of PEs in the layer
  86.     int     cols        // Number of columns of PEs in the layer
  87.     )
  88. {
  89.     DLLData *instance = allocDLLInstance(oldInstance);
  90.     return instance;
  91. }
  92.  
  93. __declspec(dllexport) void freeThresholdTransmitter(DLLData *instance)
  94. {
  95.     freeDLLInstance(instance);
  96. }
  97. */